/*
 * Author: David Welker
 * Copyright: © 2011 The Regents of the University of California
 * License: BSD
 */
 package org.jps.general;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
 
 /**
  * This class provides basic functionality that will be available for all tasks in
  * the Java Project System.
  *
  */
 public abstract class JPSTask extends Task
 {
 	/**
 	 * This method can optionally be overridden to ensure that any necessary input is present
 	 * and print an appropriate error message if it isn't.
 	 *
 	 * @return Returns true if there are no problems in the input to the command.
 	 */
 	protected boolean checkInput()
 	{
 		return true;
 	}
 	
 	/**
     * Class of type JPSTask must implement the run() method. This method throws a general 
     * exception, which can then be wrapped in a BuildException by the execute method defined 
     * below. 
     *
     * @throws Exception
     */
    public abstract void run() throws Exception;
 	
 	/**
 	 * Java Project System tasks should override this method instead of the run() method
 	 * so that they do not have to deal with build exceptions if all they are going to do
 	 * with them is throw them.
 	 */
     @Override
    public void execute() throws BuildException
    {
        try
        {
        	if( checkInput() )
            	run();
        }
        catch (Exception e)
        {
            throw new BuildException(e);
        }
    }
 }